package com.egene.tw.activity.edit;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.egene.tw.R;
import com.egene.tw.base.BaseActivity;

import org.androidannotations.annotations.ViewById;

public class EditTextActivity extends BaseActivity {

    public static Intent generate(Context context, String title, String value) {
        Intent intent = new Intent(context, EditTextActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("value", value);
        return intent;
    }

    Toolbar mToolbarView;
    TextView mToolBarTitle;
    EditText etText;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String title = getIntent().getStringExtra("title");
        String value = getIntent().getStringExtra("value");

        setContentView(R.layout.activity_edit_text);

        mToolbarView = (Toolbar) findViewById(R.id.actionBar);
        mToolBarTitle = (TextView) findViewById(R.id.toolbar_title);
        etText = (EditText) findViewById(R.id.etText);

        mToolBarTitle.setText(title);
        mToolbarView.setNavigationIcon(R.drawable.ic_back);
        mToolbarView.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        etText.setText(value);

        findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("text", etText.getText().toString());
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
